/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.kungkhies.domain.graph;

import com.kungkhies.xml.schema.kungkhie.ArcType;
import com.kungkhies.xml.schema.kungkhie.KNodeType;
import com.kungkhies.xml.schema.kungkhie.KungkhieDocument;
import java.util.HashMap;
import java.util.Map;

/**
 *
 * @author clayton
 */
public class Adjacency 
{
    private int[][] adjacencyMatrix;
    private Map<String, Integer> nodeMap = new HashMap<String, Integer>();
    private KungkhieDocument kungkhieDocument;
    private int nodeArraySize = 0;
    KNodeType[] nodeArray;

    public Adjacency()
    {
    }
    
    public Adjacency(KungkhieDocument kungkhieDocument)
    {
        this.kungkhieDocument = kungkhieDocument;
    }
    
   public void createNodeMap()
   {
       nodeArray = kungkhieDocument.getKungkhie().getKNodeList().getKNodeArray(); 
       
       System.out.println("Node array size = " + nodeArray.length);
       
       //dimension of adjacency matrix
       this.setNodeArraySize( nodeArray.length);
       
       int count = 0;
       for (KNodeType kNodeType : nodeArray)
       {
           String nodeID = kNodeType.getKNodeID();
           
           nodeMap.put(nodeID, count);
           
           count++;      
       }
   }
   
   public void createAdjacencyMatrix()
   {
       ArcType[] arcArray = kungkhieDocument.getKungkhie().getArcList().getArcArray();
       
       adjacencyMatrix = new int[this.getNodeArraySize()][this.getNodeArraySize()];
       
       for (int i = 0; i < nodeArraySize; i++)
       {
           for (int j = 0; j < nodeArraySize; j++)
           {
                adjacencyMatrix[i][j] = 0; 
           }
       }
             
       for (ArcType arcType : arcArray)
       {
           String startNodeID = arcType.getStartKNodeRef();
           String finishNodeID = arcType.getFinishKNodeRef();
          
           adjacencyMatrix[nodeMap.get(startNodeID)][nodeMap.get(finishNodeID)] = 1;    
       }
   }

    public KungkhieDocument getKungkhieDocument()
    {
        return kungkhieDocument;
    }

    public void setKungkhieDocument(KungkhieDocument kungkhieDocument)
    {
        this.kungkhieDocument = kungkhieDocument;
    }

    public int getNodeArraySize()
    {
        return nodeArraySize;
    }

    public void setNodeArraySize(int nodeArraySize)
    {
        this.nodeArraySize = nodeArraySize;
    }

    public Map<String, Integer> getNodeMap()
    {
        return nodeMap;
    }

    public void setNodeMap(Map<String, Integer> nodeMap)
    {
        this.nodeMap = nodeMap;
    }

    public int[][] getAdjacencyMatrix()
    {
        return adjacencyMatrix;
    }

    public void setAdjacencyMatrix(int[][] adjacencyMatrix)
    {
        this.adjacencyMatrix = adjacencyMatrix;
    }
    
    

}
